﻿@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager NavigationManager
<div class="top-row pl-4 navbar navbar-dark">
    <a class="navbar-brand" href="">ERCS</a>
    <button class="navbar-toggler" @onclick="ToggleNavMenu">
        <span class="navbar-toggler-icon"></span>
    </button>
</div>

<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
    <ul class="nav flex-column">
        <li class="nav-item px-3">
            <NavLink class="nav-link" href="client" Match="NavLinkMatch.All">
                <span class="oi oi-home" aria-hidden="true"></span> Home
            </NavLink>
        </li>
        <li class="nav-item px-3">
            <NavLink class="nav-link" href="client/report">
                <span class="oi oi-plus" aria-hidden="true"></span> 上报
            </NavLink>
        </li>
        <li class="nav-item px-3">
            <NavLink class="nav-link" href="#" @onclick="LogOut">
                <span class="oi oi-list-rich" aria-hidden="true"></span> 登出
            </NavLink>
        </li>
    </ul>
</div>

@code {
    private bool collapseNavMenu = true;

    private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

    private void ToggleNavMenu()
    {
        collapseNavMenu = !collapseNavMenu;
    }

    private void LogOut()
    {
        localStorage.RemoveItem("token");
        localStorage.RemoveItem("rtoken");
        NavigationManager.NavigateTo("/client/login");
    }
}
